package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppSuggest;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppSuggestDao.java
 * @Description TODO
 * @createTime 2021年07月23日 11:23:00
 */
@Repository
public class AppSuggestDao extends BaseDao<AppSuggest> {

    public void saveOrUpdate(AppSuggest appSuggest) {
        if (appSuggest.getId() == null || appSuggest.getId() == 0 ) {
            appSuggest.setId(this.add(appSuggest));
        } else {
            this.update(appSuggest);
        }

    }

    public List<AppSuggest> htfindList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        StringBuilder str = new StringBuilder("");
        str.append(" select * from app_suggest where 1=1 ");
        List<Object> list = new ArrayList<>();
        if (StringEx.isNotNull(paramap.get("userid"))) {
            str.append(" and userid = ? ");
            list.add(paramap.get("userid"));
        }
        if (StringEx.isNotNull(paramap.get("usercode"))) {
            str.append(" and usercode = ? ");
            list.add(paramap.get("usercode"));
        }
        String sql = str.toString();
        return this.queryList(sql, list, AppSuggest.class, splitPageBean);
    }

    public List<AppSuggest> list(Map<String, Object> paramap) {
        StringBuilder str = new StringBuilder("");
        str.append(" select * from app_suggest where 1=1 ");
        List<Object> list = new ArrayList<>();

        String sql = str.toString();
        return this.queryList(sql, list, AppSuggest.class);
    }

    public void delete(Integer id) {
        StringBuilder str = new StringBuilder("");
        str.append(" delete from app_suggest where id = ? ");
        ArrayList<Object> list = new ArrayList<>();
        list.add(id);
        String sql = str.toString();
        this.del(sql, list);
    }

    public void deleteByUserId(Integer userId) {
        StringBuilder str = new StringBuilder("");
        str.append(" delete from app_suggest where userid = ? ");
        ArrayList<Object> list = new ArrayList<>();
        list.add(userId);
        String sql = str.toString();
        this.del(sql, list);
    }


    /**
     * 更新用户昵称
     * @param userid
     * @param nick 昵称
     */
    public void updateNick(Integer userid,String nick){
        if(StringEx.isNull(userid)){
            return ;
        }
        if(StringEx.isNull(nick)){
            return;
        }
        String sql = " UPDATE app_suggest SET nick = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    /**
    * 更改头像
    * @Param: [userid, pic]
    * @return: void
    * @Author: zhouyunyi
    * @Date: 2021/07/5
    * @Time: 18:43
    */
    public void updatePic(Integer userid,String pic){
        if(StringEx.isNull(userid)){
            return ;
        }
        if(StringEx.isNull(pic)){
            return;
        }
        String sql = " UPDATE app_suggest SET pic = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql,paramList);
    }

}